Page({
  data: {
    showTopTips: false,
    isbn:null,
    radioItems: [
      { name: 'cell standard', value: '0' },
      { name: 'cell standard', value: '1', checked: true }
    ],
    checkboxItems: [
      { name: 'standard is dealt for u.', value: '0', checked: true },
      { name: 'standard is dealicient for u.', value: '1' }
    ],

    date: "2017-09-01",
    time: "12:01",
  },
  showTopTips: function () {
    var that = this;
    this.setData({
      showTopTips: true
    });
    setTimeout(function () {
      that.setData({
        showTopTips: false
      });
    }, 3000);
  },
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value);

    var radioItems = this.data.radioItems;
    for (var i = 0, len = radioItems.length; i < len; ++i) {
      radioItems[i].checked = radioItems[i].value == e.detail.value;
    }

    this.setData({
      radioItems: radioItems
    });
  },
  checkboxChange: function (e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value);

    var checkboxItems = this.data.checkboxItems, values = e.detail.value;
    for (var i = 0, lenI = checkboxItems.length; i < lenI; ++i) {
      checkboxItems[i].checked = false;

      for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
        if (checkboxItems[i].value == values[j]) {
          checkboxItems[i].checked = true;
          break;
        }
      }
    }

    this.setData({
      checkboxItems: checkboxItems
    });
  },
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })
  },
  bindTimeChange: function (e) {
    this.setData({
      time: e.detail.value
    })
  },
  submitForm:function(e){
    var that=this
    var ID=wx.getStorageSync('userID')
    var isbn=that.data.isbn
    var date=e.detail.value.date+' '+e.detail.value.time+':00'
    console.log(ID)
    console.log(isbn)
    console.log(date)
    console.log('--')
    wx.request({
      url: 'https://55300249.qcloud.la/JapariFriends/reserve',
      data: {
        userId: ID,
        isbn10: isbn,
        reserveDate: date
      },
      method: 'get',
      success: function (res) {
        console.log(res)
        wx.showToast({
          title: '预订成功',
          duration: 3000,
          mask: true,
        })
        // wx.navigateBack({
        //   delta: 1,
        // })
      }
    })
  },
  onLoad:function(options){
    this.setData({
      isbn:options.isbn
    })
  }
  
});